package com.situ.mall.controller.front;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.situ.mall.entity.Cart;
import com.situ.mall.entity.Order;
import com.situ.mall.entity.OrderItem;
import com.situ.mall.entity.Shipping;
import com.situ.mall.entity.User;
import com.situ.mall.service.ICartService;
import com.situ.mall.service.IOrderItemService;
import com.situ.mall.service.IOrderService;
import com.situ.mall.service.IShippingService;

@Controller
@RequestMapping("/order")
public class FrontOrderController {

	@Autowired
	private IOrderService orderService;
	
	@Autowired
	private IOrderItemService orderItemService;
	
	@Autowired
	private ICartService cartService;
	
	@Autowired
	private IShippingService shippingService;
	
//	@Autowired
//	private IOrderItemService orderItemService;
	
//	@RequestMapping("/getOrderConfirmPage.shtml")
//	public String getOrderConfirmPage() {
//		return "order_confirm";
//	}
	
	@RequestMapping("/getUserOrderInfoPage.shtml")
	public String getUserOrderInfoPage(HttpSession session, Model model) {
		User user = (User) session.getAttribute("user");
		List<Cart>list = cartService.getCartByUserId(user.getId());
		List<Cart>list2 = cartService.selectByUserIdNoChecked(user.getId());
		model.addAttribute("list", list);
		model.addAttribute("list2", list2);
		return "user_center_order";
	}
	
	@RequestMapping("/getUserSitePage.shtml")
	public String getUserSitePage(Integer userId, HttpSession session, Model model) {
		User user = (User) session.getAttribute("user");
		Shipping shipping = shippingService.getAddressInfo(userId);
		model.addAttribute("shipping", shipping);
		return "user_center_site";
	}
	
	@RequestMapping("/getUserCenterInfoPage.shtml")
	public String getUserCenterInfoPage(Integer userId, HttpSession session, Model model) {
		User user = (User) session.getAttribute("user");
		Shipping shipping = shippingService.getAddressInfo(userId);
		model.addAttribute("shipping", shipping);
		return "user_center_info";
	}
}
